package com.leyou.device;

import com.leyou.exception.MyException;
import com.leyou.vo.ExceptionResault;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 文件名：
 * 描述：
 * 作者：梁帆
 * 时间：2018/11/7
 * 版权：
 */

@ControllerAdvice //默认情况下回拦截所有的
public class MyExceptionHandler {

    @ExceptionHandler(MyException.class)
    public ResponseEntity<ExceptionResault> getError(MyException e) {
        return ResponseEntity.status(e.getMEnumException().getCode())
                .body(new ExceptionResault(e.getMEnumException()));
    }
}
